AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:Initialize()
	self.Entity:SetModel( self.IceModel )
	self.Entity:SetMaterial(self.IceMaterial)
	self.Entity:SetColor(self.IceColor.r, self.IceColor.g, self.IceColor.b, self.IceColor.a)
	self.Entity:PhysicsInit( SOLID_VPHYSICS ) 	
	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_VPHYSICS ) 
	self.Entity:SetUseType(SIMPLE_USE)  
	
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableGravity(true)
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
		phys:EnableMotion(false)
	end
	
	AM_AddOre(self.MineralName, self.MineralVol)
			
end

function ENT:SpawnFunction( ply, tr )

if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 100
	
	local ent = ents.Create( "iceroid_base" )
		ent:SetPos( SpawnPos )
		ent:Spawn()
		ent:Activate() 
	return ent
end

function ENT:OnRemove()
	local smokepuff = ents.Create( "env_ar2explosion" )
   		smokepuff:SetPos(self:GetPos())
    	smokepuff:SetKeyValue( "material", "particle/particle_noisesphere" )
    	smokepuff:Spawn()
		smokepuff:Activate()
		smokepuff:Fire("explode", "", 0)
		smokepuff:Fire("kill","",10)
		
		if self.RespawnDelay > 0 then
		    local stuff = {self:GetPos(), self:GetClass()}
			timer.Simple(self.RespawnDelay, Respawn_Roid, stuff)
		end

end

function ENT:Think()

	if self.MineralAmount <= 1 then
		self:Remove()
		return false
	end
	
	if self.MineralAmount < self.MineralMax then
		local newamount = self.MineralAmount + ((self.MineralRegen)/(60*60))
		if newamount > self.MineralMax then 
			self.MineralAmount = self.MineralMax
			--Msg(tostring(self.MineralAmount))
		else
			self.MineralAmount = newamount
			--Msg(tostring(self.MineralAmount).."\n")
		end
	end
	
	self:SetOverlayText(self.MineralName.."\n"..math.floor(self.MineralAmount))
	
	self.Entity:NextThink(CurTime()+1)
	return true --needed to override think time
			
end


